package com.bdqn.ch06.SL;


import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;

/**
 * ErrorLogger   异常处理类
 *
 * @aurhor Administrator  whs
 * @since 2024/7/15
 */

@Aspect  // 通过注解实现异常抛出增强
public class ErrorLogger {
    private static final Logger logger = Logger.getLogger("ErrorLogger.class");

    /**
     *
     * @param jp
     * @param e
     * 通过  @AfterThrowing 注解的 throwing 属性指定 抛出异常的信息 的参数名称
     */
    @AfterThrowing(pointcut = "execution(* com.bdqn.ch05.SL.Service.impl.UserServiceImpl.*(..))",throwing = "e")
    public void afterThrowing(JoinPoint jp, RuntimeException e){
        logger.error(jp.getSignature().getName()+"方法发生异常:"+ e);
    }
}
